package com.chuanyang.driverh.mainmy;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import com.chuanyang.driverh.BaseApplication;
import com.chuanyang.driverh.R;
import com.chuanyang.driverh.base.BaseTitleActivity;
import com.chuanyang.driverh.mainother.LookPhotoDetailActivity;
import com.chuanyang.driverh.responseresult.DriverInfoData;
import com.chuanyang.driverh.utils.ActivityUtil;
import com.chuanyang.driverh.utils.BitmapUtil;

import java.util.HashMap;

/**
 * Created by xupeixian on 2017/2/20.
 */

public class MyShipHadAccreditationActivity extends BaseTitleActivity {

    private DriverInfoData driverinfo;
    private ImageView iv_icon;
    private TextView tv_myship_captity;
    private TextView tv_myship_type;
    private TextView tv_myship_standard;
    private TextView tv_myship_shipname;
    private TextView tv_myship_helpcode;
    private TextView tv_myship_mmis;
    private TextView tv_myship_date;
    private ImageView iv_myship_trasportstatus;
    private RatingBar rb_myship_star;
    private TextView tv_mycar_rating;
    private ImageView iv_driver_details_ship_img1;
    private ImageView iv_driver_details_ship_img2;
    private ImageView iv_driver_details_ship_img3;
    private HashMap params;
    private TextView tv_carship_accr;
    private TextView tv_myship_hatchNum;
    private TextView tv_myship_draft;
    private TextView tv_myship_hatchsizevolume;
    @Override
    protected int getContentResId() {
        return R.layout.my_act_myshiphadaccreditation;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {

        iv_icon = (ImageView) findViewById(R.id.iv_myship_icon);
        tv_myship_captity = (TextView) findViewById(R.id.tv_myship_captity);//吨位
        tv_myship_type = (TextView) findViewById(R.id.tv_myship_type);//船只类型
        tv_myship_standard = (TextView) findViewById(R.id.tv_myship_standard);//船只规格
        //船舱口数
        tv_myship_hatchNum = (TextView) findViewById(R.id.tv_myship_hatchNum);
        //满载吃水
        tv_myship_draft = (TextView) findViewById(R.id.tv_myship_draft);
        //舱口尺寸
        tv_myship_hatchsizevolume = (TextView) findViewById(R.id.tv_myship_hatchsizevolume);
        //船只名称
        tv_myship_shipname = (TextView) findViewById(R.id.tv_myship_shipname);
        //助记号
        tv_myship_helpcode = (TextView) findViewById(R.id.tv_myship_helpcode);
        //mmis号
        tv_myship_mmis = (TextView) findViewById(R.id.tv_myship_mmis);
        //出厂日期
        tv_myship_date = (TextView) findViewById(R.id.tv_myship_date);
        //等级
        rb_myship_star = (RatingBar) findViewById(R.id.rb_myship_star);
        tv_mycar_rating = (TextView) findViewById(R.id.tv_mycar_rating);
        iv_myship_trasportstatus = (ImageView) findViewById(R.id.iv_myship_trasportstatus);

        iv_driver_details_ship_img1 = (ImageView) findViewById(R.id.iv_driver_details_ship_img1);
        iv_driver_details_ship_img2 = (ImageView) findViewById(R.id.iv_driver_details_ship_img2);
        iv_driver_details_ship_img3 = (ImageView) findViewById(R.id.iv_driver_details_ship_img3);




    }

    @Override
    protected void initData() {
        setBackImg();
        getTitleTextView().setText("船只信息");
        getRightTextView().setText("重新认证");
        driverinfo = BaseApplication.getInstance().getDriverInfo();//司机信息的常用路线只有条；
        UpdateUi();
    }



    @Override
    protected void initListener() {
        iv_driver_details_ship_img1.setOnClickListener(this);
        iv_driver_details_ship_img2.setOnClickListener(this);
        iv_driver_details_ship_img3.setOnClickListener(this);
        iv_icon.setOnClickListener(this);

    }

    @Override
    protected void baseGoEnsure() {
        ActivityUtil.startActivity(activityContext,AccredCarOrShipTeamActivity.class);
        finish();
    }


    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId())
        {
            case  R.id.iv_driver_details_ship_img1:
                ActivityUtil.startActivity(activityContext,new Intent(activityContext,LookPhotoDetailActivity.class).putExtra("data", driverinfo.getDriver().getCarPt1()));
                break;
            case  R.id.iv_driver_details_ship_img2:
                ActivityUtil.startActivity(activityContext,new Intent(activityContext,LookPhotoDetailActivity.class).putExtra("data", driverinfo.getDriver().getShipItemPt()));
                break;
//            case  R.id.iv_myship_icon:
//                startActivity(LookPhotoDetailActivity.class, driverinfo.getUserImage());
//                break;
        }
    }


    private void UpdateUi() {
        if (driverinfo != null) {
            // YncApplication.getInstance().loadCircleImage(this, driverinfo.getUserImage(), R.drawable.head_portrait, R.drawable.head_portrait, iv_icon);
            if (driverinfo.getDriver().getTransportState() == null) {
                iv_myship_trasportstatus.setImageResource(R.mipmap.free);

            }
            else {
                if (driverinfo.getDriver().getTransportState() == 1) {
                    iv_myship_trasportstatus.setImageResource(R.mipmap.transport);
                } else {
                    iv_myship_trasportstatus.setImageResource(R.mipmap.free);

                }
            }
            rb_myship_star.setRating(driverinfo.getDriver().getDriverRank());
            tv_myship_captity.setText(driverinfo.getDriver().getCapacity() + "吨");
            tv_myship_type.setText(driverinfo.getDriver().getCarType());
            tv_myship_standard.setText(driverinfo.getDriver().getCarStandard());
            tv_myship_hatchNum.setText(driverinfo.getDriver().getHatchNum()+"口");
            tv_myship_draft.setText(driverinfo.getDriver().getDraft()+"m");
            tv_myship_hatchsizevolume.setText(driverinfo.getDriver().getHatchSize()+"/"+driverinfo.getDriver().getHatchVolume()+"m³");
            tv_myship_shipname.setText(driverinfo.getDriver().getShipName());//船只名称
            tv_myship_mmis.setText(driverinfo.getDriver().getFrameNumber());//mmis号
            tv_myship_helpcode.setText(driverinfo.getDriver().getPlateNumber());//助记号
            tv_myship_date.setText(driverinfo.getDriver().getShipCreateDate());//船出厂日期
            rb_myship_star.setRating(driverinfo.getDriver().getDriverRank());
            tv_mycar_rating.setText(driverinfo.getDriver().getDriverRank()+"");
//            ratioImage(iv_driver_details_ship_img1);
//            ratioImage(iv_driver_details_ship_img2);
//            ratioImage(iv_driver_details_ship_img3);

            if(!TextUtils.isEmpty(driverinfo.getDriver().getCarPt1())){
                BitmapUtil.showImgForNetPath( driverinfo.getDriver().getInsurancePt1(),iv_driver_details_ship_img1);
                iv_driver_details_ship_img1.setVisibility(View.VISIBLE);
            } else {
                iv_driver_details_ship_img1.setVisibility(View.GONE);
            }

            if(!TextUtils.isEmpty(driverinfo.getDriver().getShipItemPt())){
                BitmapUtil.showImgForNetPath( driverinfo.getDriver().getShipItemPt(),iv_driver_details_ship_img2);
                iv_driver_details_ship_img2.setVisibility(View.VISIBLE);
            } else {
                iv_driver_details_ship_img2.setVisibility(View.GONE);
            }

        }
    }

}
